#include <gtest/gtest.h>

#include <macros.hpp>
#include <two-vector-add.hpp>

void cleanup_list(ListNode* head) {
    while (head) {
        ListNode* temp = head;
        head = head->next;
        delete temp;
    }
}

TEST(TwoVecAddTest, Exp1) {
    auto l1 = new ListNode(2, new ListNode(4, new ListNode(3)));
    auto l2 = new ListNode(5, new ListNode(6, new ListNode(4)));
    macro_test("", "7 0 8 ", 0, answer, l1, l2);
    cleanup_list(l1);
    cleanup_list(l2);
}

TEST(TwoVecAddTest, Exp2) {
    auto l1 = new ListNode(0);
    auto l2 = new ListNode(0);
    macro_test("", "0 ", 0, answer, l1, l2);
    cleanup_list(l1);
    cleanup_list(l2);
}

TEST(TwoVecAddTest, Exp3) {
    auto l1 = new ListNode(
        9,
        new ListNode(
            9,
            new ListNode(
                9, new ListNode(
                       9, new ListNode(9, new ListNode(9, new ListNode(9)))))));
    auto l2 =
        new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9))));
    macro_test("", "8 9 9 9 0 0 0 1 ", 0, answer, l1, l2);
    cleanup_list(l1);
    cleanup_list(l2);
}

TEST(TwoVecAddTest, Exp4) {
    auto l1 = new ListNode(
        9,
        new ListNode(
            9,
            new ListNode(
                9, new ListNode(
                       9, new ListNode(9, new ListNode(9, new ListNode(9)))))));
    auto l2 =
        new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9))));
    macro_test("", "8 9 9 9 0 0 0 1 ", 0, ai_answer, l1, l2);
    cleanup_list(l1);
    cleanup_list(l2);
}

TEST(TwoVecAddTest, Exp5) {
    auto l1 = new ListNode(
        9,
        new ListNode(
            9,
            new ListNode(
                9, new ListNode(
                       9, new ListNode(9, new ListNode(9, new ListNode(9)))))));
    auto l2 =
        new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9))));
    macro_test("", "8 9 9 9 0 0 0 1 ", 0, official_answer, l1, l2);
    cleanup_list(l1);
    cleanup_list(l2);
}

int main(int argc, char* argv[]) {
    testing::InitGoogleTest(&argc, argv);
    int result = RUN_ALL_TESTS();
    return result;
}